package com.nowcoder.community.utils;/**
 * 功能描述
 *
 * @author 21775
 * @date 2022/09/15  22:21
 */

import com.nowcoder.community.entity.User;
import org.springframework.stereotype.Component;

/**
 *@ClassName HostHolder
 *@Description TODO 持有用户信息，代替session
 *@Author 21775
 *@Date 2022/9/15 22:21
 *@Version 1.0
 */
@Component
public class HostHolder {

    private ThreadLocal<User> users = new ThreadLocal<>();

    public void setUser(User user) {
        users.set(user);
    }

    public User getUser() {
        return users.get();
    }

    public void clear() {
        users.remove();
    }

}
